/*******************************************************************************
 *
 * Copyright (c) 2008-2011 ayound@gmail.com, guwei8576431@gmail.com
 * This program and the accompanying materials
 * are made available under the terms of the GNU GENERAL PUBLIC LICENSE 
 * which accompanies this distribution, and is available at
 * http://dev.perl.org/licenses/gpl1.html
 * All rights reserved.
 * 
 * Created on 2009-11-8
 *******************************************************************************/

package org.cgtw.scriptprofile.ui;

import java.awt.BorderLayout;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import org.cgtw.scriptprofile.server.listener.IProfileDataChangeListener;
import org.cgtw.scriptprofile.widget.ProfileTableViewer;

public class StatisticViewPane extends JPanel implements IProfileDataChangeListener{

	private JTable table;
	private JScrollPane scrollPane;
	
	public StatisticViewPane(){
		super();
		BorderLayout layout = new BorderLayout();
		this.setLayout(layout);
		scrollPane = new JScrollPane();
		this.add(scrollPane, BorderLayout.CENTER);
	}
	
	public void load(){
		table = new ProfileTableViewer();
		this.scrollPane.getViewport().add(table);
		int[] columnWidths = new int[]{90, 50, 90, 110, 90, 90, 90, 90, 100};
	    for (int i = 0; i < columnWidths.length-1; i++) {
	    	table.getColumnModel().getColumn(i).setPreferredWidth(columnWidths[i]);
	    	table.getColumnModel().getColumn(i).setMaxWidth(columnWidths[i]);
	    	table.getColumnModel().getColumn(i).setMinWidth(columnWidths[i]);
	    }
	}

	public void change() {
		if(table != null){
			this.remove(table);
		}
		this.load();
	}
	
}
